package com.wuliupai.delivery.wuliupaidelivery.activity;

import android.widget.ImageView;
import android.widget.TextView;

import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.wuliupai.delivery.wuliupaidelivery.R;
import com.wuliupai.delivery.wuliupaidelivery.bean.BaseBean;
import com.wuliupai.delivery.wuliupaidelivery.bean.MyInfoBean;
import com.wuliupai.delivery.wuliupaidelivery.utils.ImageLoaderUtils;

import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.Extra;
import org.androidannotations.annotations.ViewById;

import java.util.List;

@EActivity(R.layout.activity_my_profile)
public class MyProfileActivity extends AppBaseActivity {

    @ViewById(R.id.iv_my_profile_head_portrait)
    ImageView iv_my_profile_head_portrait; //头像

    @ViewById(R.id.tv_my_profile_name)
    TextView tv_my_profile_name; //名字

    @ViewById(R.id.tv_my_profile_gender)
    TextView tv_my_profile_gender;//性别

    @ViewById(R.id.tv_my_profile_territory)
    TextView tv_my_profile_territory;//负责区域

    @ViewById(R.id.tv_my_profile_license_number)
    TextView tv_my_profile_license_number; //车牌号

    @ViewById(R.id.tv_my_profile_phone_num)
    TextView tv_my_profile_phone_num;//手机号

    @Extra("name")
    String name;
    @Extra("sex")
    String sex;
    @Extra("area")
    List<MyInfoBean> area;
    @Extra("driverNum")
    String driverNum;
    @Extra("headUrl")
    String headUrl;

    @AfterViews
    void onPageStart() {
        setDefaultTitle(this, R.string.string_my_profile_title);
        initView();
    }

    /**
     * 初始化数据
     */
    private void initView() {
        BaseBean baseBean = new BaseBean();
        String phone = baseBean.getLoginName();
        DisplayImageOptions options = ImageLoaderUtils.loadImage(MyProfileActivity.this, 0, R.mipmap.my_portrait);
        ImageLoader.getInstance().displayImage(headUrl, iv_my_profile_head_portrait,
                options);
        tv_my_profile_name.setText(name);
        tv_my_profile_gender.setText(sex);
        StringBuffer areaStr = new StringBuffer();
        for (int i = 0; i < area.size(); i++) {
            areaStr.append(area.get(i).getAreaName()).append("、");
        }
        if (area.size() > 0) {
            areaStr.deleteCharAt(areaStr.length() - 1);
        }
        tv_my_profile_territory.setText(areaStr);
        tv_my_profile_license_number.setText(driverNum);
        tv_my_profile_phone_num.setText(phone);
    }

}
